package com.cmd.driver;

import com.alibaba.fastjson.JSONObject;
import com.mgr.UserOrderMgr;
import com.player.DriverUser;
import com.player.User;
import com.qy.bean.OrderInfo;
import com.qy.util.StaticData;
import com.util.AbstractCommand;
import com.util.PBMessage;

/**
 * 司机检车完毕
 * @author zwl 2018年2月1日
 */
public class OrderCheckOverCMD extends AbstractCommand {

    @Override
    public void execute(User user, PBMessage packet) throws Exception {

	JSONObject reJs = new JSONObject();
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	JSONObject param = packet.getMessage();
	if (!param.containsKey("orderId")) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.param_error.getType());
	    user.sendPacket(reJs);
	    return;
	}
	DriverUser dUser = (DriverUser) user;
	// 订单号
	int orderId = param.getInteger("orderId");
	if(dUser.getServerOrder().getOrderId()!=orderId){
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.NOT_THIS_DRIVER.getType());
	    user.sendPacket(reJs);
	    return;
	}
	
	OrderInfo info = UserOrderMgr.getOrderInfo(orderId);
	if (info == null) {
	    reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.not_exist.getType());
	    user.sendPacket(reJs);
	    return;
	}
	//检车完毕重新发单
	info.setOrderStatus(StaticData.OrderStatus.COMPLET_CHECK_NOT_ACCEPT.getType());
	//即时保存
	UserOrderMgr.update(info);
	
	reJs.put(StaticData.reKey.code.getKey(),StaticData.codeType.ok.getType());
	reJs.put(StaticData.reKey.cmd.getKey(),packet.getCode());
	user.sendPacket(reJs);
	return;
    }

}
